-module(quek_utf8_utf16).
-export([conv/1]).

conv(Utf8) when Utf8 < 16#100 ->
    Utf8;
conv(Utf8) when Utf8 < 16#10000 ->
    <<A, B>> = Utf8,
    X = ((A band 00011100) bsl 2) bor (A band 2#00000011),
    Y = (B band 2#00111111),
    <<Utf16:16>> = <<X, Y>>,
    Utf16;
conv(Utf8) when Utf8 < 16#1000000 ->
    <<A, B, C>> = Utf8,
    X = (A band 2#00001111) bsl 4,
    Y1 = (B band 2#00111100) bsr 2,
    Y2 = (B band 2#00000011) bsl 6,
    Z = C band 2#00111111,
    <<Utf16:16>> = <<(X bor Y1), (Y2 bor Z)>>,
    Utf16;
conv(Utf8) ->
    <<A, B, C, D>> = Utf8,
    W = (A band 2#00000111) bsl 2,
    X1 = (B band 2#00110000) bsr 4,
    X2 = (B band 2#00001111) bsl 4,
    Y1 = (C band 2#00111100) bsl 2,
    Y2 = (C band 2#00000011) bsr 6,
    Z = D band 2#00111111,
    <<Utf16:32>> = <<0, (W bor X1), (X2 bor Y1), (Y2 bor Z)>>,
    Utf16.

     
    
